<?php

namespace App\Excels\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithDrawings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class ProjectMallDetailExport implements FromCollection,WithStyles, WithDrawings,WithTitle
{
    protected mixed $data;
    protected mixed $ifMy;

    public function __construct($data,$ifMy){
        $this->data = $data;
        $this->ifMy = $ifMy;
    }

    public function collection(): Collection
    {
        //
        $xlsData = [
            [
                "日期",
                "营业额",
                "分账金额",
                "应结金额",
                "实收差异",
            ]
        ];
        foreach($this->data as $data){
            $tmp = [
                $data["date"],
                $data["income"],
                $data["back_money"] <= 0 ? "未分账" : (string) ($this->ifMy ? $data["myBackMoney"] : $data["back_money"]),
                (string) ($this->ifMy ? $data["myExpectedMoney"] : $data["expected_money"]),
                (string) ($this->ifMy ? $data["myBackDiffMoney"] : $data["back_diff_money"]),

            ];
            $xlsData[] = $tmp;
        }

        return collect($xlsData);
    }
    public function styles(Worksheet $sheet){

    }
    public function drawings(){
        return [];
    }
    public function title(): string
    {
        return "工作表1";
    }
}

